package com.hy.service.impl;

import com.hy.dao.NewInformationDao;
import com.hy.dao.UserDao;
import com.hy.service.NewInformationService;
import com.hy.utils.ResponseResult;
import com.hy.utils.ResultUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class NewInformationServiceImpl implements NewInformationService {
    private NewInformationDao newInformationDao = new NewInformationDao();

    @Override
    public void listRecentlyInterestMe(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Integer userId = Integer.valueOf(request.getParameter("userId"));
        List<Map<String, Object>> mapList = newInformationDao.selectRecentlyInterestMe(userId);

        List<Map<String, Object>> list = new ArrayList<>();
        for (Map<String, Object> map : mapList) {
            list.add(newInformationDao.selectUserById(String.valueOf(map.get("user_id"))));
        }

        ResponseResult<List<Map<String, Object>>> result = new ResponseResult<>(200, "ok", list, 101);
        ResultUtils.result(result,request,response);
    }

    @Override
    public void listLikesMy(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String userId = request.getParameter("userId");

        List<Map<String, Object>> list = newInformationDao.selectLikesMy(Integer.valueOf(userId));

        ResponseResult<List<Map<String, Object>>> result = new ResponseResult<>(200, "ok", list, 101);
        ResultUtils.result(result,request,response);
    }
}
